﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace ClassLibrary
{
    public abstract class DataAccess<T> : IDataAccess
    {
        const String ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\FysioDB.mdf;Integrated Security=True;User Instance=True";

	    public bool Save(IContent obj, string table)
	    {
		    try
		    {
			    using (SqlConnection connection = new SqlConnection(ConnectionString))
			    using (SqlTransaction tx = connection.BeginTransaction())
			    {
				    SqlCommand command = connection.CreateCommand();
				    command.CommandText = string.Format("INSERT INTO {0} (CPR, Description) VALUES ('{1}', '{2}')",
						table, obj.Cpr, obj.Description);

				    command.ExecuteNonQuery();
				    tx.Commit();
			    }
		    }
		    catch (Exception)
		    {
			    return false;
		    }
			
		    return true;
	    }

	    public bool Update(IContent objectToUpdate, string table)
	    {
		    throw new NotImplementedException();
	    }

	    public bool Delete(IContent objectToDelete, string table)
	    {
		    throw new NotImplementedException();
	    }

	    public IContent Load(int idOfObjectToLoad, string table)
	    {
		    throw new NotImplementedException();
	    }

	    public List<IContent> LoadAll(string table)
	    {
		    throw new NotImplementedException();
	    }
    }
}
